package com.xmy.cultivate.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmy.cultivate.entity.RenewClassCollect;
import com.xmy.cultivate.service.IRenewClassCollectService;
import com.xmy.cultivate.util.Code;
import com.xmy.cultivate.util.PageResult;
import com.xmy.cultivate.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 续班汇总表 前端控制器
 * </p>
 *
 * @author min
 * @since 2022-09-01
 */
@RestController
@RequestMapping("/api/renewClassCollect")
@Scope("prototype")
public class RenewClassCollectController {


    @Autowired
    IRenewClassCollectService iRenewClassCollectService;

    @GetMapping()
    public Result findAll(@RequestParam Map reMap){
        Integer pageNum = StringUtils.isEmpty((String)reMap.get("pageNum")) ? 1 : Integer.valueOf((String)reMap.get("pageNum"));
        Integer pageSize = StringUtils.isEmpty((String)reMap.get("pageSize")) ? 10: Integer.valueOf((String)reMap.get("pageSize"));

        Page<RenewClassCollect> page = new Page<>(pageNum,pageSize);


        String yearPart = (String) reMap.get("yearPart");//年份
        String schoolId = (String) reMap.get("schoolId");//校区
        String quarterNum = (String) reMap.get("quarterNum");//季度

        String orderAllCount = (String) reMap.get("orderAllCount");//总带班人数
        String orderRenewCount = (String) reMap.get("orderRenewCount");//应续人数
        String orderYetRenewCount = (String) reMap.get("orderYetRenewCount");//已续人数
        String orderLossingCount = (String) reMap.get("orderLossingCount");//流失人数
        String orderRenewRate = (String) reMap.get("orderRenewRate");//续班率
        String orderLossingRade = (String) reMap.get("orderLossingRade");//流失

        String tearcherName = (String) reMap.get("tearcherName");//老师名称




        QueryWrapper<RenewClassCollect> queryWrapper =  new QueryWrapper<>();
        //queryWrapper.apply("1=1");

        queryWrapper.eq(StringUtils.isNotBlank(yearPart),"year_part",yearPart);
        queryWrapper.eq(StringUtils.isNotBlank(schoolId),"school_id",schoolId);
        queryWrapper.eq(StringUtils.isNotBlank(quarterNum),"quarter_num",quarterNum);
        queryWrapper.like(StringUtils.isNotBlank(tearcherName),"teacher_name",tearcherName);


        IPage<Map<String,Object>> iPage = iRenewClassCollectService.findAll(page,queryWrapper);
        return new Result(Code.OK,new PageResult(iPage.getRecords(),iPage.getTotal(),iPage.getPages()));
    }


    /**
     * 续班人数
     * @return
     */
    @GetMapping("/personNum")
    public Result personNum(@RequestParam Map reMap){
        return new Result(Code.OK);
    }
}
